package org.linlinjava.litemall.admin.web;

import java.time.LocalDateTime;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallAccountLog;
import org.linlinjava.litemall.db.service.LitemallAccountLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/account/log")
@Validated
public class LitemallAccountLogController {
  private final Log logger = LogFactory.getLog(LitemallAccountLogController.class);

  @Autowired
  private LitemallAccountLogService accountLogService;


  @RequiresPermissions("admin:account-log:list")
  @RequiresPermissionsDesc(menu = {"账户管理", "流水管理"}, button = "查询")
  @GetMapping("/list")
  public Object list(//
      Integer accountId, //
      @RequestParam(required = false) @DateTimeFormat(
          pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
      @RequestParam(required = false) @DateTimeFormat(
          pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime end,
      @RequestParam(defaultValue = "1") Integer page, //
      @RequestParam(defaultValue = "10") Integer limit, //
      @Sort @RequestParam(defaultValue = "create_time") String sort, //
      @Order @RequestParam(defaultValue = "asc") String order//
  ) {
    List<LitemallAccountLog> list =
        accountLogService.querySelective(accountId, start, end, page, limit, sort, order);
    return ResponseUtil.okList(list);
  }
}
